import React, { Component } from 'react';
import AppThemeMode from './AppThemeMode';

const ThemeCompetent = (WrappedComponent: JSX.IntrinsicAttributes) => {
  return class extends Component {
    static navigationOptions = WrappedComponent.navigationOptions;

    componentWillMount() {
      AppThemeMode.addListener(this._AppThemeModeChange);
    }

    _AppThemeModeChange = () => {
      // try {
      //   this.forceUpdate();
      // } catch (e) {

      // }
    }

    componentWillUnmount() {
      AppThemeMode.removeListener(this._AppThemeModeChange);
    }

    render() {
      return <WrappedComponent {...this.props} />;
    }
  };
};

// eslint-disable-next-line import/prefer-default-export
export { ThemeCompetent };
